home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / net / tf02.lha / TinyFugue / tf-lib / tr.tf < prev    next >
Text File  |  1995-08-12  |  785b  |  26 lines

  1. ;;;; Character translation
  2. ;;; usage:  /tr <domain> <range> <string>
  3. ;;; <domain> and <range> are lists of charcters.  Each character in <string>
  4. ;;; that appears in <domain> will be translated to the corresponding
  5. ;;; character in <range>.
  6.  
  7. ;;; Example:
  8. ;;; command: /def biff = /tr OIS. 01Z! $[toupper({*})]
  9. ;;; command: /biff TinyFugue is cool wares, dude.
  10. ;;; output:  T1NYFUGUE 1Z C00L WAREZ, DUDE!
  11.  
  12. /~loaded tr.tf
  13.  
  14. /def -i tr = \
  15.     /let old=%1%;\
  16.     /let new=%2%;\
  17.     /let tail=%-2%;\
  18.     /let dest=%;\
  19.     /while /let i=$[strchr(tail, old)]%; /test i >= 0%; /do \
  20.         /let j=$[strchr(old, substr(tail, i, 1))]%;\
  21.         /let dest=$[strcat(dest, substr(tail,0,i), substr(new, j, 1))]%;\
  22.         /let tail=$[substr(tail,i+1)]%;\
  23.     /done%;\
  24.     /echo -- %{dest}%{tail}
  25.  
  26.